package sunyan.dao;

import sunyan.entity.SunYanEntity;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate4.HibernateTemplate;
import org.springframework.orm.hibernate4.support.HibernateDaoSupport;
import org.springframework.stereotype.Component;

import java.util.List;

@Component()
public class SunYanDao  extends HibernateDaoSupport {





    public List<SunYanEntity> queryPage(String name) {

        String sql = "select * from j06sunyan where name like ? ";
        Query query=getSessionFactory().openSession().createSQLQuery(sql);
        query.setParameter(0,  "%" + name + "%");
        //将查询结果转成Map对象的集合
        // query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
        query.setResultTransformer(Transformers.aliasToBean(SunYanEntity.class));
        List<SunYanEntity> list=  query.list();

        return  list;
    }
}
